<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/27 0027
 * Time: 01:42
 */

//与unix 的egrep命令类似的操作

//返回数组中所有的合法IP地址
$address = [
    '212.187.38.47','188.141.21.91','2.9.256.7'
];
$res = preg_grep('/^((\d?\d|1\d\d|2[0-4]\d|25[0-5])\.){3}(\d?\d|1\d\d|2[0-4]\d|25[0-5]){1,3}/',$address);
//array(2) {
//    [0]=>
//  string(13) "212.187.38.47"
//    [1]=>
//  string(13) "188.141.21.91"
//}
var_dump($res);
